plugins: VOsc/VOsc3 - fix crash with negative buffer numbers
[supercollider.git] / examples / GUI examples / scimage_animation.scd
blob811d5317e66e6fc1ca5ffbf91571bfd89cde35a6
3         // SCImage animation example - from a code of Tom Tlalim, adapted for SCImage by blackrain
4         
5         var w, h = 800, v = 600, seed = Date.seed, phase=0, phasef = 0.00125, zoom = 1, zoomf = 1.01, trans=0.1, run = true, i=0, amess, ind=0;
6         var size = 100, mess, ordered;
7         var image,
8         
9         export=false;           // <--- toggle to export frames
11         w = Window("animation", Rect(40, 40, h, v));
12         
13         w.view.background_(Color.white);
14         u = UserView.new(w, Rect(0, 0, h, v));
15         w.front;
17         // image preparation
18         image =  SCImage.new(h@v);
19         image.lockFocus;
20         Color.black.set;
21         Pen.fillRect(Rect(0,0,h,v));
22         image.unlockFocus;
24         mess = [{1.0.rand2}!200, {1.0.rand2}!200, {1.0.rand2}!200];
25         size = mess[0].size;
27         u.drawFunc = {
28         
29                 image.drawAtPoint(0@0);
30                         
31         };
33         {
34                 while { run } {
36                     phase = phase+phasef;
37                     zoom = zoom*zoomf;
38                     amess = mess;
39                     
40                         //{
41                                 image.lockFocus;
42                                 
43                                     Pen.use {
44                                         Pen.color = Color.black.alpha_(0.1);
45                                         Pen.fillRect(Rect(0,0,h, v));
46                                         Pen.strokeColor = Color.grey(1,0.7);
47                                         (mess[0].size * (zoom*0.1).min(1)).do {
48                                             var x, y, z;
49                                             #x, y, z = [amess[0][i], amess[1][i],  amess[2][i]];
50                                             Pen.addRect(
51                                                 Rect(
52                                                 (x*0.5+1)*400, 
53                                                 (z.neg*0.5+0.75)*400, 
54                                                 (y.neg)*100 + (z*0.5 +1)*(zoom/5), 
55                                                 (y.neg)*100  + (z*0.5+1)*(zoom/5)
56                                                 )
57                                             );
58                                             i=(i+1)%((mess[0].size));
59                                         };
61                                                 Pen.stroke;
62                                                 
63                                                 i = (mess[0].size/(zoom));
64                                         
65                                         }; // End of Pen.use
66                                 
67                                 image.unlockFocus;                              
68                                 
69                                 if(export, {
70                                         image.write(Document.current.path.dirname ++ "/SavedImage_"++ind++".jpeg");
71                                 });
72                         
73                         //}.bench; // bench to tune it 
74                 
75                         u.refresh;
76                         
77                         0.05.wait;
78                         
79                         ind=ind+1;
80                 }
81                 
82         }.fork(AppClock);
84         w.onClose_({
85         
86                 run = false;
87                 {
88                         image.free;
89                 }.defer(0.3); // enough to release safely
90         
91         });